﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.OleDb;
namespace DAO
{
    public class CTHoaDonDAO
    {
        public List<CTHoaDonDTO> LapHoaDon(string MaBH)
        {
            string sql = "SELECT ctpb.MaBH,ctpb.MaSP,ctpb.MaKH,ctpb.SLBan,ctpb.DonGia,ctpb.ThanhTien,kh.TenKH,kh.DChi,kh.DThoai,sp.TenSP,pb.NgayBH";
            sql+=" FROM CTPHIEUBAN ctpb,KHACHHANG kh,SANPHAM sp, PHIEUBAN pb";
            sql+=" WHERE ctpb.MaKH=kh.MaKH AND ctpb.MaSP=sp.MaSP AND ctpb.MaBH=pb.MaBH AND ctpb.MaBH = '" + MaBH + "'";
            OleDbConnection conn = new OleDbConnection();
            conn = DataProvider.ConnectDB();
            OleDbCommand cmd = new OleDbCommand(sql, conn);
            OleDbDataReader reader = cmd.ExecuteReader();
            List<CTHoaDonDTO> DanhSach = new List<CTHoaDonDTO>();

            while (reader.Read())
            {
                CTHoaDonDTO cthdDTO = new CTHoaDonDTO();
               // cthdDTO.MaCTPB = reader.GetString(0);
                cthdDTO.MaBH = reader.GetString(0);
                cthdDTO.MaSP = reader.GetString(1);
                cthdDTO.MaKH = reader.GetString(2);
                cthdDTO.SLBan = reader.GetInt32(3);
                cthdDTO.DonGia = reader.GetInt32(4);
                cthdDTO.ThanhTien = reader.GetDouble(5);
                cthdDTO.TenKH = reader.GetString(6); 
                cthdDTO.DiaChi = reader.GetString(7); 
                cthdDTO.DThoai = reader.GetString(8); 
                cthdDTO.TenSP = reader.GetString(9);
                cthdDTO.NgayBH = reader.GetDateTime(10);
                DanhSach.Add(cthdDTO);
            }
            conn.Close();
            return DanhSach;
        }
    }
}
